home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Environments / PowerFantasm™ 4.05 / F4_EXAMPLES / PPC_Graphics_demo / PPC_graph_demo.s < prev   
Encoding:
Text File  |  1996-06-21  |  6.2 KB  |  228 lines  |  [TEXT/edF6]

  1. *******************************
  2. **Fantasm V4 PowerPC demo #1
  3. **A PowerPC assembly language example program just for fun.
  4. **Opens a window and runs various graphical tests
  5. **Runs in any colour mode.
  6. **File:PPC_graph_demo.s
  7. **Date: 3rd Dec.95
  8. **©Lightsoft 1995.
  9.  
  10. **Normal Mac init stuff
  11.  
  12. param1:    reg    r3        *Set up the names of the regs used for parameter passing
  13. param2:    reg    r4
  14. param3: reg    r5
  15. param4:    reg    r6
  16. bss:    reg    r30        *The register we use for global data
  17. **Note that if calling system calls, r31 must remain intact, so we simply don't use it.
  18. ;    title    "demo"
  19. ;    input    "None."
  20. ;    output    "None."
  21. ppc_graph_demo:
  22.         
  23.     ENTRY            *Prog starts here    
  24.     start_up        *save all the regs and set up r30 for global
  25.     la    r3,qd(`bss)    *get the address of the QD array into r3
  26.     addic    r3,r3,206-4
  27.     Xcall    InitGraf    *Init managers
  28.     Xcall    InitFonts
  29.     Xcall    InitWindows
  30.     Xcall    InitMenus
  31.     Xcall    TEInit
  32.     li    `param1,0        
  33.     Xcall    InitDialogs
  34.     Xcall    InitCursor
  35.     
  36. **Open our window and copy its viewrect.
  37.     bl    graph_demo_init    *initialise and open a window and get its viewrect into viewrect_1(bss)
  38. **now the drawing
  39. **lets start with some nice horizontal lines
  40. **First lets set the foreground colour to white
  41.     lwz    `param1,white(rtoc)
  42.     Xcall    RGBForeColor    *That should do it
  43. **now a simple horiz test line - draw r22 white lines
  44.     la    r3,viewrect_1(`bss)    *top,left,bott,right
  45.     lhz    r20,2(r3)    *left of window
  46.     lhz    r21,6(r3)    *right of window
  47.     lhz    r22,4(r3)    *bottom
  48.  
  49. **use MoveTo and LineTo to draw the line
  50. line_loop:
  51.     bl    draw_line    *draw a line
  52.     subic.    r22,r22,1    *up 1 line
  53.     bne-    line_loop    *and if line y isn't zero draw another line.
  54.     
  55. **now we'll do the same, but change the colours dynamically this time and 
  56. **fill the window 50 times
  57.     li    r26,50        *do it all 50 times
  58. outer_loop:
  59. **reset the x and y's
  60.     la    r3,viewrect_1(`bss)    *top,left,bott,right
  61.     lhz    r20,2(r3)    *left of window
  62.     lhz    r21,6(r3)    *right of window
  63.     lhz    r22,4(r3)    *bottom
  64.  
  65. **Draw line and alter the components of the colour
  66. line_loop_2:
  67.     bl    draw_line    *draw this line
  68.     lwz    r23,white1(rtoc)    *r23 points to our colour that we are altering
  69.  
  70.     lhz    r24,(r23)    *get the red value
  71.     subic    r24,r24,64    *subtract 64 from the red
  72.     sth    r24,(r23)    *save the new colour back in memory
  73.  
  74.     lhz    r24,2(r23)    *get the green value
  75.     subic    r24,r24,32    *subtract 32 from the green
  76.     sth    r24,2(r23)    *save the new colour back in memory
  77.  
  78.     lhz    r24,4(r23)    *get the blue value
  79.     subic    r24,r24,128    *subtract 128 from the blue
  80.     sth    r24,4(r23)    *save the new colour back in memory
  81.     
  82.     lwz    `param1,white1(rtoc)
  83.     Xcall    RGBForeColor    *Set new forground colour to white1
  84.  
  85.     subic.    r22,r22,1    *up 1 line
  86.     bne    line_loop_2    *and if not top of window (line=0) draw next line in new colour.
  87.     
  88.     subic.    r26,r26,1    *do it all r26 times
  89.     bne    outer_loop
  90.  
  91.  
  92.     bl    clear_window    *clear the window out by scrolling
  93.  
  94. **now lets draw a circles
  95.     li    r28,3        *do the zoomy circles 3 times
  96. rgb_zooms:
  97.     lwz    `param1,red(rtoc)
  98.     Xcall    RGBForeColor    *Set new forground colour
  99.     bl    draw_circles    *draw a zoomy circle in red.
  100.  
  101.     lwz    `param1,green(rtoc)
  102.     Xcall    RGBForeColor    *Set new forground colour
  103.     bl    draw_circles    *draw a zoomy circle in green
  104.  
  105.     lwz    `param1,blue(rtoc)
  106.     Xcall    RGBForeColor    *Set new forground colour
  107.     bl    draw_circles    *draw a zoomy circle in blue
  108.     subic.    r28,r28,1
  109.     bne    rgb_zooms
  110.     tidy_up            *restore all the regs back to how they were before this prog started.
  111.     blr            *bye bye - end of program.
  112.  
  113.  
  114. *****************
  115. **Drawing subroutine follow
  116. draw_circles:
  117.     mflr    r29        *save return addr.
  118. **First reduce our viewrect_2 down to a small size
  119.     la    r20,viewrect_1(`bss)    *copy this rect
  120.     la    r22,viewrect_2(`bss)    *to this rect whilst making it smaller
  121.     lhz    r21,(r20)
  122.     addic.    r21,r21,100
  123.     sth    r21,(r22)    *top+100
  124.     
  125.     lhz    r21,2(r20)
  126.     addic.    r21,r21,100
  127.     sth    r21,2(r22)    *left+100
  128.  
  129.     lhz    r21,4(r20)
  130.     subic.    r21,r21,100
  131.     sth    r21,4(r22)    *bottom-100
  132.  
  133.     lhz    r21,6(r20)
  134.     subic.    r21,r21,100
  135.     sth    r21,6(r22)    *right-100
  136.  
  137.     li    r26,100        *loop count
  138. **Now drow r26 circles, each slightly larger than the last    
  139. circles:
  140.     la    `param1,viewrect_2(`bss)    *top,left,bott,right    
  141.     Xcall    PaintOval            *simple?
  142.  
  143.     la    r20,viewrect_2(`bss)    
  144.     lhz    r21,(r20)
  145.     subic.    r21,r21,2
  146.     sth    r21,(r20)    *top-2
  147.     
  148.     lhz    r21,2(r20)
  149.     subic.    r21,r21,2
  150.     sth    r21,2(r20)    *left-2
  151.  
  152.     lhz    r21,4(r20)
  153.     addic.    r21,r21,2
  154.     sth    r21,4(r20)    *bottom+2
  155.  
  156.     lhz    r21,6(r20)
  157.     addic.    r21,r21,2
  158.     sth    r21,6(r20)    *right+2
  159.  
  160.     subic.    r26,r26,1
  161.     bne    circles
  162.     mtlr    r29
  163.     blr
  164.  
  165. *************************************************
  166. **Draws a horizontal line in the forground colour.
  167. **Needs start x in r20, end x in r21 and y in r22
  168. draw_line:
  169.     mflr    r29
  170.     mr    `param1,r20
  171.     mr    `param2,r22
  172.     Xcall    MoveTo
  173.     mr    `param1,r21
  174.     mr    `param2,r22
  175.     Xcall    LineTo
  176.     mtlr    r29
  177.     blr                *easy innit?
  178. ************************************************************************************
  179. **Clears our window by first scrolling diagonally, and then virtically (virtically?).
  180. clear_window:
  181.     mflr    r29        *this is a subroutine, so save return address.
  182. **First lets set the foreground colour to white
  183.     lwz    `param1,white(rtoc)
  184.     Xcall    RGBForeColor    *That should do it
  185.  
  186. *extern pascal void ScrollRect(const Rect *r, short dh, short dv, RgnHandle updateRgn)
  187. **Get height/2 in r22
  188.     la    r20,viewrect_1(`bss)
  189.     lhz    r22,4(r20)    *bottom for use as a loop counter
  190.  
  191. **Scroll diagonally    
  192. scroll_diag_loop:
  193.     la    `param1,viewrect_1(`bss)    *top,left,bott,right    
  194.     li    `param2,1    *dh = delta horizontal = 1 pixel
  195.     li    `param3,1    *dv = delta vertical = 1 pixel = diagonal scroll.
  196.     li    `param4,0    *updatergn
  197.     Xcall    ScrollRect    *scroll by 1 pixels
  198.     subic.    r22,r22,1    *Decrement loop count
  199.     bne    scroll_diag_loop    *and branch if not zero to scroll again
  200.  
  201.     la    r20,viewrect_1(`bss)
  202.     lhz    r22,4(r20)    *bottom for use as loop counter
  203. **Scroll down    
  204. scroll_down_loop:
  205.     la    `param1,viewrect_1(`bss)    *top,left,bott,right    
  206.     li    `param2,0    *dh
  207.     li    `param3,1    *dv
  208.     li    `param4,0    *updatergn
  209.     Xcall    ScrollRect    *scroll by 1 pixel
  210.     subic.    r22,r22,1    *Decrement loop count
  211.     bne    scroll_down_loop    *and branch if not zero to scroll again
  212.  
  213.     mtlr    r29        *get return address
  214.     blr
  215. *********************************************************
  216. **Predefined Data that goes in the data section
  217. **Our colours defined as red,green,blue strengths.
  218. white:    dc.h    0xffff,0xffff,0xffff
  219. white1:    dc.h    0xffff,0xffff,0xffff
  220. red:    dc.h    0xffff,0,0
  221. green:    dc.h    0,0xffff,0
  222. blue:    dc.h    0,0,0xffff
  223. ****
  224. *********************************************************
  225. **The declarations.
  226.     global    ppc_graph_demo
  227.     extern    graph_demo_init    *External initialisation subroutine in graph_demo_init.s
  228.